#include <cv.h>
#include <highgui.h>
void main()
{
  IplImage* image = 0;
  CvCapture* capture = cvCaptureFromCAM(0);
  int Key = 0;
  cvNamedWindow( "Capture", 0 );
  cvResizeWindow( "Capture", 320, 240 );
  int saveCnt = 0;
  char buf[0xff] = {0};
  bool isExit = false;

  printf("Press S key to save... (press q to exit...)\n");

  printf("Test : %f\n",cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH));
  printf("Suc : %d\n",cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH,320.0f));
  printf("Suc : %d\n",cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT,240.0f));
      
  while(!isExit) {
       //cvGrabFrame( capture );
       image = cvQueryFrame( capture );

	   if(image == NULL)
		   break;

	   Key = cvWaitKey(10);

       cvShowImage( "Capture", image );

	   switch(Key)
	   {
	   case 's':
	   case 'S':
		   sprintf(buf,"image%04d.jpg",saveCnt++);
		   cvSaveImage(buf,image);
		   printf("%s saved.\n",buf);
		   break;
	   case 'q':
	   case 'Q':
		   isExit = true;
		   break;
	   default:
		   break;
	   }
  }

  cvReleaseCapture( &capture );
  cvDestroyWindow( "Capture" );
}